package com.mikasa.springboot.dubbo.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.mikasa.springboot.dubbo.api.IDubboDemoService;
import com.mikasa.springboot.dubbo.model.Comic;
import com.mikasa.springboot.dubbo.model.ComicResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author User
 * @date 17/1/20
 */

@RestController
@RequestMapping("dubbo")
public class IDubboController {

    private static final Logger LOGGER = LoggerFactory.getLogger(IDubboController.class);

    @Value("${com.user.name}")
    private String userName;

    @Reference(version="1.0.0",group="test",timeout=2000)
    private IDubboDemoService iDubboDemoService;

    @GetMapping("/test")
    public Object test(){

        LOGGER.info(".   ____          _            __ _ _\n" +
                " /\\\\ / ___'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\\n" +
                "( ( )\\___ | '_ | '_| | '_ \\/ _` | \\ \\ \\ \\\n" +
                " \\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )\n" +
                "  '  |____| .__|_| |_|_| |_\\__, | / / / /\n" +
                " =========|_|==============|___/=/_/_/_/");

        LOGGER.info("dubbo服务调用测试开始...");
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("userName",userName);
        String dubboResult = iDubboDemoService.sayHello(userName);
        map.put("dubboResult",dubboResult);

        Comic comic = new Comic();
        comic.setId(1);
        comic.setType(1);
        comic.setName("银魂");

        ComicResult comicResult = iDubboDemoService.handleComic(comic);
        map.put("comicResult",comicResult);

        return map;
    }

}
